/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package broadcast;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 *
 * @author Xuan Cau
 */
public class Broadcast {

    /**
     * @param args the command line arguments
     */
   public static void main(String args[]) throws Exception
{
    String Broadcastaddress = new String("255.255.255.255");
    int port = 9875;
    DatagramSocket serverSocket = new DatagramSocket();
    serverSocket.setBroadcast(true);
    InetAddress IPAddress = InetAddress.getByName(Broadcastaddress);
    System.out.println("Sending Discovery message to " + IPAddress + "Via UDP port " + port);

    byte[] sendData = new byte[4];
    sendData[0] = 'F';
    sendData[1] = 'I';
    sendData[2] = 'N';
    sendData[3] = 'D';

    DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length,IPAddress,port);

   // while (true)
    {
        serverSocket.send(sendPacket);
        System.out.println("Packet sent");
    }
}
}
